<?php
namespace App\Utils\Service\Ly;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class JwtServer
{
    /**
     * 加密
     * @param $uid
     * @param int $expire
     * @return string
     */
    public static function encode($uid,$expire=7200)
    {
        $key = '2008A';
        $payload = [
            'uid' => $uid,
            'expire' => time()+$expire,
        ];
        return JWT::encode($payload, $key, 'HS256');
    }

    /**
     * 解密
     * @param $jwt
     * @return array
     */
    public static function decode($jwt)
    {
        $key = '2008A';
        $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
        return (array)$decoded;
    }
}
